/*
Created by: X
http://www.createdbyx.com/

The XMLDocContentProcessor library is licenced under the 
Creative Commons Attribution-NonCommercial-ShareAlike 2.5 Canada
http://creativecommons.org/licenses/by-nc-sa/2.5/ca/
*/
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using System.IO;
using System.Xml;
using System.Text;

namespace XMLDocContentProcessor
{
    public class XMLDocumentReader : ContentTypeReader<XmlDocument>
    {

        protected override XmlDocument Read(ContentReader input, XmlDocument existingInstance)
        {

            // calc the number of characters that will be read
            int count = (int)(input.BaseStream.Length - input.BaseStream.Position);

            // create a string reader to store the data that will be read
            StringBuilder sb = new StringBuilder(count, count);

            // read "count" number of characters from the input object and append the data
            // to the StringBuilder varible
            sb.Append(input.ReadChars(count));

            // create a new XmlDocument object
            XmlDocument Doc = new XmlDocument();

            // attempt to load the data stored in the sb object into the Doc object by
            // wrapping the data in a StringReader object
            Doc.Load(new StringReader(sb.ToString()));

            // return the reference the Doc varible
            return Doc;
        }
    }
}
